package cn.zwxky.android.staff.Jurisdiction.Technology;

import android.view.View;
import android.widget.ExpandableListView;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.Event.LsfbEvent;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * Created by Administrator on 2017/4/10 0010.
 */
@ContentView(R.layout.aty_saddress_book)
public class TaskAlloActivity2 extends LsfbActivity {

    /**
     * 二级列表
     */
    @ViewInject(R.id.aty_addpunishment_listview)
    private ExpandableListView listView;

    private List<TaskAlloBean.ListBean> mList;

    private TaskAlloAdapter2 adapter;

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "选择接收人");

        mList = new ArrayList<>();
        adapter = new TaskAlloAdapter2(this, mList);
        listView.setAdapter(adapter);

        listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {

                return true;
            }
        });
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

                return false;
            }
        });
    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    public void getData() {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        new BaseInternet().getData_Get(URLString.TASK_ALLO, hashMap, TaskAlloBean.class, new TaskAlloEvent<TaskAlloBean>(), true, true);
    }

    @EventAnnotation
    public void TaskAlloEvent(TaskAlloEvent<TaskAlloBean> event) {
        switch (event.getCode()) {
            case 200:
                mList.clear();
                mList.addAll(event.getData().getList());
                if (mList.size() > 0) {
                    for (int i = 0; i < mList.size(); i++)
                        listView.expandGroup(i);
                }
                adapter.notifyDataSetChanged();
                break;
            default:
                SN.SnackShow(listView, event.getMsg());
                break;
        }
    }

    @EventAnnotation
    public void TaskAlloClickEvent3(TaskAlloClickEvent3 event3) {

        TaskAlloClickEvent4 even = new TaskAlloClickEvent4();
        even.setData(event3.getData());
        LsfbEvent.getInstantiation().post(even);
        finish();

    }

}
